package com.lemon.smartsafetynew.ui.adapter.common;

import android.view.View;
import android.widget.Button;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.entity.event.base.AppEvent;
import com.lemon.smartsafetynew.entity.event.EventTagConstants;
import com.lemon.smartsafetynew.entity.event.common.ViewEvent;
import com.lemon.smartsafetynew.entity.me.MeRcvItemBase;

import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/7/27.
 */

public class SectionEndButtonView implements AdapterItem<Object> {

    private Button button;

    @Override
    public int getLayoutResId() {
        return R.layout.item_bottom_button;
    }

    @Override
    public void bindViews(View root) {

        button = (Button)root.findViewById(R.id.end_btn);

    }

    @Override
    public void setViews() {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppService.getBus().post(new ViewEvent(EventTagConstants.ME_LOGOUT_TAG));
            }
        });
    }

    @Override
    public void handleData(Object object, int position) {

        if(object instanceof MeRcvItemBase) {

            MeRcvItemBase itemBase = (MeRcvItemBase)object;
            String string = (String)itemBase.getData();
            button.setText(string);
        }

    }
}
